package q1742_countBalls;

import java.util.HashMap;
import java.util.Map;

public class Solution_1 {
    /*
    盒子中小球的最大数量
     */
    public int countBalls(int lowLimit, int highLimit) {
        Map<Integer, Integer> map = new HashMap<>();
        int ans = 0;
        for (int i = lowLimit; i <= highLimit; ++i) {
            int cur = countNumber(i);
            map.put(cur, map.getOrDefault(cur, 0) + 1);
            ans = Math.max(ans, map.get(cur));
        }
        return ans;
    }
    public int countNumber(int cur) {
        int ans = 0;
        while (cur != 0) {
            ans += cur % 10;
            cur /= 10;
        }
        return ans;
    }
}
